<template>
	<view :style="{ '--color': color }">
		<status-bar :title="title"></status-bar>

		<view class="shopBox">
			<image :src="$imgUrls(storeInfo.logo)" mode="aspectFill" class="shopImg"></image>
			<view class="Box">
				<view class="d-flex a-center">
					<view class="classTip" v-if="storeInfo.bussName">{{ storeInfo.bussName }}</view>
					<text class="color_33 size28">{{ storeInfo.name }}</text>
				</view>
				<text class="color_33 size26 m-top10">{{ storeInfo.address }}</text>
			</view>
		</view>

		<view class="viewbox auto m-top24">
			<view class="row j-sb a-center">
				<text class="black size30 bold">订单/流水</text>
				<view class="d-flex a-center" @click="show = true">
					<text class="color_333 size28">{{ monthData }}</text>
					<view class="iconfont icon-xiangxia1 color_333 size30 p-left10 bold"></view>
				</view>
			</view>
		</view>

		<view class="info">
			<view class="list">
				<text class="size36 color_333">{{ thisM.teamOrderNum }}</text>
				<text class="size28 color_333 m-top4"> 当月单量</text>
			</view>
			<view class="list">
				<text class="size36 color_333">{{ thisM.teamOrderMoney }}</text>
				<text class="size28 color_333 m-top4"> 当月流水</text>
			</view>
			<view class="list">
				<text class="size36 color_333">{{ thisM.teamIncome }}</text>
				<text class="size28 color_333 m-top4"> 当月收益</text>
			</view>
		</view>

		<view class="chanList" v-for="(item, index) in pageData" :key="index">
			<view class="enBox">
				<text class="orderTxt">订单号：{{ item.order_code }}</text>
				<view
					class="d-flex a-center m-bot10"
					v-if="item.v_headimg || item.v_name || item.v_tel">
					<image
						:src="$imgUrls(item.v_headimg)"
						mode="aspectFill"
						class="v_headimg"
						v-if="item.v_headimg"></image>
					<view class="v_name">
						<text class="color_33 size28 ellipsis">{{ item.v_name }}</text>
					</view>
					<text class="color_33 size28">({{ item.v_tel }})</text>
				</view>
				<text class="orderTxt">金额：￥{{ item.payment }}</text>
				<text class="orderTxt">下单时间：{{ item.add_date }}</text>
			</view>
			<view class="earnings">
				<text class="color h6">收益</text>
				<text class="color size30">{{ item.income }}</text>
			</view>
		</view>

		<emptys v-if="!pageData.length"></emptys>
		<u-datetime-picker
			:show="show"
			ref="datetimePicker"
			v-model="value1"
			:formatter="formatter"
			:maxDate="maxDate"
			@cancel="show = false"
			@confirm="confirm"
			mode="year-month"></u-datetime-picker>
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	export default {
		data() {
			return {
				title: '门店业绩',
				img: 'https://msraimgcdn.mogoie.com/6137/1731484174751.jpg',
				show: false,
				value1: Number(new Date()),
				maxDate: Number(new Date()),
				monthData: '',
				page: 1,
				limit: 10,
				getMore: true,
				store_id: '',
				team: 0,
				storeInfo: '',
				thisM: '',
				pageData: [],
			};
		},
		onLoad(opt) {
			if (opt.store_id) this.store_id = opt.store_id;
		},
		onShow() {
			this.monthData = this.$pop.tampToDate(new Date());
			this.OrderList();
		},
		onReady() {
			// 微信小程序需要用此写法
			this.$refs.datetimePicker.setFormatter(this.formatter);
		},
		methods: {
			OrderList() {
				this.$http
					.post({
						url: '/trdxcxApi/getStoreOrderList',
						data: {
							page: this.page,
							limit: this.limit,
							store_id: this.store_id,
							team: this.team,
							scanDate: this.monthData + '-01',
						},
					})
					.then((res) => {
						if (res.errcode != '100') return this.$Toast(res.msg);
						this.storeInfo = res.storeInfo;
						if (res.storeInfo.name) this.title = res.storeInfo.name;
						this.thisM = res.thisM;
						const result = res.data || [];
						this.page == 1
							? (this.pageData = result)
							: (this.pageData = [...this.pageData, ...result]);
						if (result.length < this.limit) this.getMore = false;
					});
			},
			confirm(e) {
				const result = this.$pop.tampToDate(e.value);
				this.value1 = e.value;
				this.monthData = result;
				this.show = false;
				this.page = 1;
				this.getMore = true;
				this.OrderList();
			},
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`;
				}
				if (type === 'month') {
					return `${value}月`;
				}
				if (type === 'day') {
					return `${value}日`;
				}
				return value;
			},
		},
		computed: {
			...mapState(['color']),
		},
		onReachBottom() {
			if (!this.getMore) return;
			this.page++;
			this.OrderList();
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #f2f2f2;
		padding-bottom: 24rpx;
	}
</style>
<style lang="scss" scoped>
	.shopBox {
		width: 690rpx;
		margin: 24rpx auto 0;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 20rpx;
		display: flex;
		align-items: center;

		.shopImg {
			width: 100rpx;
			height: 100rpx;
			border-radius: 10rpx;
			margin-right: 20rpx;
		}

		.Box {
			flex: 1;
			display: flex;
			flex-direction: column;

			.classTip {
				padding: 2rpx 10rpx;
				background-color: var(--color);
				color: #fff;
				font-size: 20rpx;
				margin-right: 10rpx;
			}
		}
	}

	.info {
		width: 690rpx;
		margin: 24rpx auto 0;
		box-sizing: border-box;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		padding: 24rpx;
		border-radius: 10rpx;
		margin-top: 20rpx;

		.list {
			display: flex;
			flex-direction: column;
			align-items: center;
		}
	}

	.chanList {
		width: 690rpx;
		margin: 24rpx auto 0;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 24rpx;
		position: relative;
		display: flex;
		align-items: center;
		overflow: hidden;
		box-sizing: border-box;

		.qubue {
			color: #000;
			font-size: 28rpx;
			font-weight: bold;
			position: absolute;
			top: 10rpx;
			right: 24rpx;
		}

		.enBox {
			flex: 1;
			display: flex;
			flex-direction: column;

			.orderTxt {
				color: #333;
				font-size: 28rpx;
				line-height: 50rpx;
			}
			.v_headimg {
				width: 60rpx;
				height: 60rpx;
				border-radius: 50%;
				margin-right: 10rpx;
			}
			.v_name {
				max-width: 220rpx;
			}
		}

		.earnings {
			display: flex;
			flex-direction: column;
			text-align: right;
			align-self: flex-end;
		}
	}
</style>
